﻿#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#endregion

namespace WpfFootball.Parser
{
    /// <summary>
    /// Provides a couple of search operations.
    /// </summary>
    public class Searcher
    {
        #region Fields
        private static List<string> teams;
        private static IOManager ioManager;
        #endregion

        public static void Init()
        {
            teams = new List<string>();
            ioManager = IOManager.Instance();
            teams = ioManager.GetAvailableTeamNames().ToList();
        }

        /// <summary>
        /// Looks up for a team name.
        /// </summary>
        /// <param name="keyWord">The keyword to be used in the search process.</param>
        /// <returns>The best team name that matches the keyword.</returns>
        public static string SearchTeam(string keyWord)
        {
            string teamName = teams.Find(delegate(string str) { return str.ToLower().StartsWith(keyWord.ToLower()); });
            return teamName;
        }

        /// <summary>
        /// Checks if a team name exists in the application database.
        /// </summary>
        /// <param name="teamName">The name of the team to search.</param>
        /// <returns>true if the team name exists in the database, false otherwise.</returns>
        public static bool TeamNameExists(string teamName)
        {
            return teams.Contains(teamName);
        }

        /// <summary>
        /// Checks if a team is already managed by the application.
        /// </summary>
        /// <param name="teamName">The name of the team to check.</param>
        /// <returns></returns>
        public static bool ManagedTeamExists(string teamName)
        {
            return ioManager.ManagedTeamExists(teamName);
        }
    }
}
